package com.open.party.cloud.view.msg.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.open.party.cloud.R;
import com.open.party.cloud.model.MsgEntity;
import com.sinothk.android.utils.XUtils;
import com.sinothk.view.image.rounded.RoundedImageView;

import java.util.ArrayList;
import java.util.List;

import com.sinothk.android.utils.inters.OnSuperListener;

public class MsgListForMeAdapter extends RecyclerView.Adapter<MsgListForMeAdapter.ViewHolder> {

    // 展示数据
    private ArrayList<MsgEntity> mData;
    private Context mContext;
    private OnSuperListener<MsgEntity> superListener;

    public MsgListForMeAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

    public void setOnSuperListener(OnSuperListener<MsgEntity> superListener) {
        this.superListener = superListener;
    }

    public void setData(List<MsgEntity> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<MsgEntity> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.msg_main_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // 绑定数据
        final MsgEntity itemData = mData.get(position);

        holder.titleTv.setText(XUtils.string().getNotNullValue(itemData.getNoticeContent()));
//        holder.recStatusTv.setText(XUtils.string().getNotNullValue(itemData.getRecStatus()));
//        holder.orgNameTv.setText("发布人：" + itemData.getOrgName());
        if (itemData.getCreateTime() == null) {
            holder.timeTv.setText("近期");
        } else {
            String dateTimeStr = XUtils.date().getDateStrByDate(itemData.getNoticeTime(), "yyyy年MM月dd日");
            holder.timeTv.setText(dateTimeStr);
        }
//
//        Picasso.get().load(itemData.getImg())
//                .error(R.drawable.icon_default_img)
//                .placeholder(R.drawable.icon_default_img)
//                .into(holder.imageView);
//
//        holder.recProgressTv.setText(XUtils.string().getNotNullValue(itemData.getRecProgress(), "0%"));
//        holder.recNumTv.setText(XUtils.string().getNotNullValue(itemData.getRecNum(), "0") + "人");
//        holder.perNumTv.setText(itemData.getPerNum() + "人");
//
//        String days = XUtils.date().getTwoDateInterval2(new Date(), itemData.getRecruitEndDate());
//        if (days.contains("-")) {
//            holder.recDaysTv.setText("0天");
//        } else {
//            holder.recDaysTv.setText(days);
//        }
//
        if (superListener != null) {
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    superListener.onClick(position, itemData, "");
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout rootView;
        TextView titleTv, recStatusTv, orgNameTv, timeTv, recProgressTv, recNumTv, perNumTv, recDaysTv;
        RoundedImageView imageView;

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);

            titleTv = itemView.findViewById(R.id.titleTv);
//            recStatusTv = itemView.findViewById(R.id.recStatusTv);
//            orgNameTv = itemView.findViewById(R.id.orgNameTv);
            timeTv = itemView.findViewById(R.id.timeTv);
//
//            recProgressTv = itemView.findViewById(R.id.recProgressTv);
//            recNumTv = itemView.findViewById(R.id.recNumTv);
//            perNumTv = itemView.findViewById(R.id.perNumTv);
//            recDaysTv = itemView.findViewById(R.id.recDaysTv);
//
//            imageView = itemView.findViewById(R.id.imageView);
        }
    }
}